@extends('develop.layoutList')

@section('title')
    <li class="cur">
        <span>流水号管理</span>
    </li>
@endsection
@section('css')
    <style>
        .form-group{margin-bottom:9px; padding:0px;}
    </style>

@endsection

@section('btn')
    <button class="btn btn-primary" type="button" onclick="seqno.edit();">添加</button>
@endsection

@section('search')

<input type="text"  class="form-control" name="name" id="name" value="" style="width:150px;" placeholder="请输入流水号名称">
<input type="text"  class="form-control" name="remark" id="remark" value="" style="width:150px;" placeholder="请输入备注">

@endsection

@section('js')
    <script>

        var bootstrap_table_ajax_url = '/lar/develop/seqno/search';
        bootstrap_table({
        sortName: 'seqno', //排序字段
        sortOrder: 'DESC',//排序方式
        columns: [ //字段
            { title: '操作', field: 'operate', align: 'center' },
            { title: '流水号名称', field: 'name', align: 'left'},
            { title: '流水号', field: 'seqno', align: 'left' },
            { title: '备注',  field: 'remark', align: 'left' }
        ]
    });

    var seqno = {

        //保存、编辑
        edit: function ( name ) {

            var html='<form id="pop_form" onsubmit="return false;" class="form-horizontal" role="form" style="margin-top: 10px">';
            html+='<input type="hidden" id="seqno" name="seqno" value="">';
            html+='<div class="form-group">';
            html+='<label class="col-sm-3 control-label" for="name"><span class="red">*</span>流水号名称：</label>';
            html+='<div class="col-sm-7">';
            html+='<input class="form-control"  type="text" id="name" name="name" placeholder="请输入流水号名称"  value=""  autocomplete="off" />';
            html+='</div>';
            html+='</div>';
            html+='<div class="form-group">';
            html+='<label class="col-sm-3 control-label" for="seqno"><span class="red">*</span>流水号：</label>';
            html+='<div class="col-sm-7">';
            html+='<input class="form-control"  type="text" id="seqnoID" name="seqnoID"  placeholder="请输入流水号" value=""  autocomplete="off" />';
            html+='</div>';
            html+='</div>';
            html+='<div class="form-group">';
            html+='<label class="col-sm-3 control-label" for="remark"><span class="red">*</span>备注：</label>';
            html+='<div class="col-sm-7">';
            html+='<input class="form-control"  type="text" id="remark" name="remark"  placeholder="请输入流水号备注" value=""  autocomplete="off" />';
            html+='</div>';
            html+='</div>';
            html+='</form>';

            seqno.reset();
            var title ="";

            if ( name ) {
                title = "修改流水号";
                seqno.name = name;
            } else {
                title ="添加流水号";
            }

            layer.open({
                type:1,
                title: title,       //弹出层标题
                area:'600px',
                content:html,
                btn: ['确定', '取消'],
                yes: function(){
                    seqno.store( name );
                },
                btn2: function(){
                    seqno.close();
                }
            });

            if ( name ) {
                var load_index = layer.load();

                E.ajax({
                    type:'get',
                    url:'/lar/develop/seqno/get/' + name,
                    success: function ( obj ) {
                        layer.close(load_index);
                        if (obj.code == 200) {
                            $('#pop_form').find('#seqno').val(obj.data.seqno);
                            $('#pop_form').find('#name').val(obj.data.name);
                            $('#pop_form').find('#seqnoID').val(obj.data.seqno);
                            $('#pop_form').find('#remark').val(obj.data.remark);
                            $('#pop_form').find('#name').attr('disabled','disabled');
                            $('#pop_form').find('#remark').attr('disabled','disabled');
                        } else {
                            layer.alert(obj.message,{icon:2});
                        }
                    }
                });
            }
        },

        //保存校验
        store:function( name ) {

            var formData = E.getFormValues('pop_form');

            var msg = '';

            if ( E.isEmpty(formData.name) ) {
                msg += '请输入流水号名称<br/>';
            }
            if ( E.isEmpty(formData.seqnoID) ) {
                msg += '请输入流水号<br/>';
            }
            if ( E.isEmpty(formData.remark) ) {
                msg += '请输入流水号备注<br/>';
            }
            if ( !E.isEmpty( msg ) ) { //存在错误，返回不进行提交
                layer.alert(msg,{icon:2});
                return false;
            }

            layer.confirm("您确认保存流水号吗？",{icon:3}, function ( ) {
                var layer_index = layer.load();
                E.ajax({
                    type:'get',
                    url:'/lar/develop/seqno/store',
                    data:formData,
                    dataType:'json',
                    success:function ( obj ) {
                        layer.close(layer_index);

                        if ( obj.code == 200 ) {
                            layer.alert( obj.message, {icon:1,time:1500 });
                            seqno.reset();
                            seqno.load();
                        } else {
                            layer.alert(obj.message,{icon:2});
                        }
                    }
                });
            });
        },

        //重置弹出层
        reset: function () {
            $('#pop_form').find('#seqno').val("");
            $('#pop_form').find('#name').val("");
            $('#pop_form').find('#seqnoID').val("");
            $('#pop_form').find('#remark').val("");
            $('#pop_form').find('#name').attr('disabled',false);
            $('#pop_form').find('#remark').attr('disabled',false);

        },

        //删除流水号
        del:function( name ) {

            layer.confirm('确认删除这个流水号吗?',{icon:3}, function () {
                var load_index = layer.load();
                E.ajax({
                    type:'get',
                    url:'/lar/develop/seqno/delete/'+name,
                    success:function( obj ) {
                        layer.close(load_index);
                        if( obj.code == 200 ) {
                            layer.alert( obj.message, {icon:1,time:1500 } );
                            seqno.close();
                            seqno.load();
                        }else{
                            layer.alert(obj.message,{icon:2});
                        }
                    }
                });
            });
        },

        //重新加载表格
        load: function() {
            //刷新表格
            $('#table').bootstrapTable('refresh');
        },

        close:function(){
            layer.closeAll();
        }

    }

</script>
@endsection